package com.mxx.qh.network.http;

import android.util.Log;

import com.mxx.qh.App;
import com.mxx.qh.SPUtils;

import org.jetbrains.annotations.NotNull;

import java.io.IOException;

import okhttp3.Interceptor;
import okhttp3.Response;

/**
 * @ClassName: ReceivedCookiesInterceptor
 * @Description: java类作用描述
 * @Author: ljf89 (刘江飞)
 * @Date: 2021/1/13-- 9:20
 * @Email: 642371742@qq.com
 */
public class ReceivedCookiesInterceptor implements Interceptor {
    @NotNull
    @Override
    public Response intercept(Interceptor.Chain chain) throws IOException {
        Response originalResponse = chain.proceed(chain.request());
        if (!originalResponse.headers("Set-Cookie").isEmpty()) {
            //解析Cookie
            for (String header : originalResponse.headers("Set-Cookie")) {
                Log.i("TAG", header);
                if (header.contains("token=")) {
                    String s = header.substring(header.indexOf("token="), header.indexOf(";"));
                    Log.i("TAG", s);
                }
            }

        }
        if (originalResponse.headers("Cookie").isEmpty()) {
            //解析Cookie
            for (String header : originalResponse.headers("Cookie")) {
                Log.i("TAG", header);
//                if (header.contains("token=")) {
//                    String s = header.substring(header.indexOf("token="), header.indexOf(";"));
//                    Log.i("TAG", s);
//                }
            }

        }
        return originalResponse;
    }
}
